#!/usr/bin/env python3
import sys
import re
import math
from dataclasses import dataclass

@dataclass
class Beacon:
    l: (int, int, int)

class Scanner:
    sid: int
    beacons: list[Beacon]

    def __init__(self, sid: int, beacons: list[Beacon]):
        self.sid = sid
        self.beacons = beacons
    
    def __str__(self):
        return f'scanner {self.sid}: ' + ', '.join([ f'b: {b.l}' for b in self.beacons ])

ORIENTATIONS = [
    (1, 0, 2, 1, 1, -1),
    (1, 2, 0, 1, 1, 1),
    (1, 0, 2, 1, -1, 1),
    (1, 2, 0, 1, -1, -1),
    (2, 1, 0, -1, 1, 1),
    (0, 1, 2, 1, 1, 1), 
    (2, 1, 0, 1, 1, -1),
    (0, 1, 2, -1, 1, -1),
    (2, 0, 1, 1, 1, 1),
    (0, 2, 1, -1, 1, 1),
    (2, 0, 1, -1, -1, 1),
    (0, 2, 1, 1, -1, 1),
    (0, 2, 1, -1, 1, -1),
    (2, 0, 1, -1, -1, -1),
    (0, 2, 1, 1, -1, -1),
    (2, 0, 1, 1, 1, -1),
    (1, 0, 2, -1, 1, 1),
    (1, 2, 0, -1, -1, 1),
    (1, 0, 2, -1, -1, -1),
    (1, 2, 0, -1, 1, -1),
    (2, 1, 0, -1, -1, 1),
    (0, 1, 2, 1, -1, -1),
    (2, 1, 0, -1, -1, -1),
    (0, 1, 2, -1, -1, 1),
]

def generate_orientations(beacon):
    for o in ORIENTATIONS:
        yield Beacon((beacon.l[o[0]] * o[3], beacon.l[o[1]] * o[4], beacon.l[o[2]] * o[5]))

PATTERNS = [ re.compile(r'$'), re.compile(r'--- scanner ([0-9]+) ---$'), re.compile(r'(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)$') ]

scanners = []

for line in sys.stdin:
    print(line.rstrip('\n'))
    for i, p in enumerate(PATTERNS):
        match = re.match(p, line.rstrip('\n'))
        if match:
            if i == 0: continue
            if i == 1:
                scanners.append(Scanner(match.groups()[0], []))
                continue
            if i == 2:
                groups = [int(m) for m in match.groups()]
                assert(len(groups) == 3)
                scanners[-1].beacons.append(Beacon(groups))
                continue

for scanner in scanners:
    print(scanner)

def dist(l):
    return math.sqrt(l[0]**2 + l[1]**2 + l[2]**2)

for b1 in scanners[0].beacons:
    for b2 in scanners[1].beacons:
        for o1 in generate_orientations(b1):
            for o2 in generate_orientations(b2):
                if dist(o1.l) == dist(o2.l):
                    print('yay')